Quiz
C++
This quiz has question types that open in the usual player.
Questions in this quiz (89)
1#include [blank_start]<iostream>[blank_end]
using namespace std;
int main() {
return 0;
}- A<iostream>
2#include <iostream>
[blank_start]using namespace std;[blank_end]
int main() {
return 0;
}- Ausing namespace std;
3#include <iostream>
using namespace std;
int main() {
cout [blank_start]<<"[blank_end]Hello World"<<endl;
return 0;
}- A<<"
4#include <iostream>
using namespace std;
[blank_start]int main()[blank_end] {
return 0;
}- Aint main()
5#include <iostream>
using namespace std;
int main() {
cout << "Hello World! [blank_start]\n[blank_end]";
return 0;
}
Line other than endl- A\n
6#include <iostream>
using namespace std;
int main() {
[blank_start]//[blank_end]cout << "Hello World! \n";
cout << "I am learning C++";
return 0;
}
Comment out the first output line- A//
7#include <iostream>
using namespace std;
int main() {
[blank_start]/*[blank_end]cout << "Hello World! \n\n";
cout << "I am learning C++";*/
return 0;
}- A/*
8int myNum = 15; // myNum is 15
myNum = 10;
cout << myNum;
OUTPUT:
[blank_start]10[blank_end]- A10
9int x = 5;
int y = 6;
[blank_start]int[blank_end] sum = x + y;
cout << sum;- Aint
10[blank_start]int[blank_end] x = 5, y = 6, z = 50;
cout << x + y + z;- Aint
11You should always declare the variable as constant when you have values that are unlikely to change:
[blank_start]const[blank_end] float PI = 3.14;- Aconst
12Take input from x:
int x;
cout << "Type a number: ";
[blank_start]cin >> x[blank_end];
cout << "Your number is: " << x;- Acin>>x
13Size of int
- A8
- B1
- C4
- D6
14Size of double
- A4
- B8
- C1
- D2
15Size of float
- A6
- B1
- C8
- D4
16Size of char
- A4
- B8
- C2
- D1
17Size of boolean
- A1
- B8
- C4
- D2
18[blank_start]float[blank_end] myNum = 5.75;
cout << myNum;- Afloat
19[blank_start]double[blank_end] myNum = 19.994434;
cout << myNum;- Adouble
20[blank_start]int[blank_end] myNum = 1000;
cout << myNum;- Aint
21bool isCodingFun = true;
cout << isCodingFun;
Output:
[blank_start]1[blank_end]- A1
22bool isCodingFun = false;
cout << isCodingFun;
Output:
[blank_start]0[blank_end]- A0
23[blank_start]char[blank_end] a = 65, b = 66, c = 67;
cout << a;
cout << b;
cout << c;
Output:
ABC- Achar
24#include [blank_start]<string>[blank_end]
string greeting = "Hello";
cout << greeting;- A<string>
25Adds together two values
x [blank_start]+[blank_end] y- A+
26Subtracts one value from another
x [blank_start]-[blank_end] y- A-
27Multiplies two values
x [blank_start]*[blank_end] y- A*
28Divides one value by another
x [blank_start]/[blank_end] y- A/
29Returns the division remainder
x [blank_start]%[blank_end] y- A%
30Increases the value of a variable by 1
[blank_start]++x[blank_end]- A++x
31Decreases the value of a variable by 1
[blank_start]--[blank_end]x- A--
32int x = 5;
x[blank_start]+=[blank_end]3;
cout << x << endl;
Output:
8- A+=
33int x = 5;
x[blank_start]-=[blank_end]3;
cout << x << endl;
Output:
2- A-=
34int x = 5;
x[blank_start]*=[blank_end]3;
cout << x << endl;
Output:
15- A*=
35int x = 5;
x[blank_start]/=[blank_end]3;
cout << x << endl;
Output:
1.6666- A/=
36int x = 5;
x[blank_start]%=[blank_end]3;
cout << x << endl;
Output:
2- A%=
37int x=5,y=2;
x == y;
x != y;
x > y;
x < y;
x >= y;
x <= y;- Af,t,t,t,t,t
- Bf,f,t,t,f,f
- Ct,t,t,f,t,t
- Df,t,t,f,t,f
38Returns true if both statements are true
int x=4
cout <<x < 5 [blank_start]&&[blank_end] x < 10<<endl;
output:
true- A&&
39 Returns true if one of the statements is true
int x=6
cout <<x < 5 || x < 10<<endl;
output:
[blank_start]true[blank_end]- Atrue
40Reverse the result, returns false if the result is true
int x=3
cout <<[blank_start]<<endl;
output:
false- A!
41
#include [blank_start]<string>[blank_end]
string greeting = "Hello";- A<string>
42string firstName = "John ";
string lastName = "Doe";
string fullName = firstName [blank_start]+[blank_end] lastName;
cout << fullName;
Output:
John Doe- A+
43 string firstName = "John";
string lastName = "Doe";
string fullName = firstName + [blank_start]" "[blank_end] + lastName;
cout << fullName;- A" "
44string firstName = "John ";
string lastName = "Doe";
string fullName = firstName[blank_start].append[blank_end](lastName);
cout << fullName;- A.append
45string x = "10";
string y = "20";
string z = x + y;
Ouput:
[blank_start]1020[blank_end]- A1020
46string x = "10";
int y = 20;
string z = x + y;
Output:
[blank_start]error[blank_end]- Aerror
47string txt = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
cout << "The length of the txt string is: " << [blank_start]txt.length()[blank_end];
Output:
Print length of string- Atxt.length()
48string txt = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
cout << "The length of the txt string is: " << [blank_start]txt.size()[blank_end];
Print length other than length()- Atxt.size()
49string myString = "Hello";
cout << [blank_start]myString[2][blank_end];
// Output l- AmyString[2]
50string myString = "Hello";
[blank_start]myString[blank_end][0] = 'J';
cout << myString;- AmyString
51string firstName;
cout << "Type your first name: ";
[blank_start]cin>>firstName[blank_end];
cout << "Your name is: " << firstName;
Take Input of the string- Acin>>firstName
52string fullName;
cout << "Type your full name: ";
[blank_start]getline[blank_end](cin, fullName);
cout << "Your name is: " << fullName;- Agetline
53#include <iostream>
#include <string>
int main() {
std::string greeting = "Hello";
[blank_start]std::[blank_end]cout << greeting;
return 0;
}
Other than using namespace std;- Astd::
54cout<<[blank_start]max(5,10)[blank_end];
Give maximum of 5 and 10- Amax(5,10)
55cout<<[blank_start]min(5,10)[blank_end];
Give minimum of 5 and 10- Amin(5,10)
56cout << [blank_start]sqrt([blank_end]64);
find sqrt- Asqrt(
57cout << [blank_start]round[blank_end](2.6);
round it ofrf- Around
58int x = 20;
int y = 18;
[blank_start]if[blank_end] (x > y) {
cout << "x is greater than y";
}- Aif
59int time = 20;
if (time < 18) {
cout << "Good day.";
} [blank_start]else[blank_end] {
cout << "Good evening.";
}
// Outputs "Good evening."- Aelse
60int time = 22;
if (time < 10) {
cout << "Good morning.";
} [blank_start]else if[blank_end] (time < 20) {
cout << "Good day.";
} else {
cout << "Good evening.";
}
// Outputs "Good evening."- Aelse if
61int day = 4;
[blank_start]switch[blank_end] (day) {
case 1:
cout << "Monday";
break;
case 2:
cout << "Tuesday";
break;
case 3:
cout << "Wednesday";
break;
case 4:
cout << "Thursday";
break;
case 5:
cout << "Friday";
break;
case 6:
cout << "Saturday";
break;
case 7:
cout << "Sunday";
break;
}- Aswitch
62int day = 4;
switch (day) {
case 6:
cout << "Today is Saturday";
break;
case 7:
cout << "Today is Sunday";
break;
[blank_start]default:[blank_end]
cout << "Looking forward to the Weekend";
}
// Outputs "Looking forward to the Weekend"- Adefault:
63int i = 0;
[blank_start]while[blank_end] (i < 5) {
cout << i << "\n";
i++;
}- Awhile
64int i = 0;
[blank_start]do[blank_end] {
cout << i << "\n";
i++;
}
while (i < 5);- Ado
65[blank_start]for[blank_end] (int i = 0; i <= 10; i = i + 2) {
cout << i << "\n";
}- Afor
66for (int i = 0; i < 10; i++) {
if (i == 4) {
[blank_start]break[blank_end];
}
cout << i << "\n";
}
Stop the loop when i = 4- Abreak
67for (int i = 0; i < 10; i++) {
if (i == 4) {
[blank_start]continue[blank_end];
}
cout << i << "\n";
}
Skip printing 4- Acontinue
68string cars[blank_start][4][blank_end];
create array with 4 strings to store- A[4]
69string cars[blank_start][4][blank_end] = {"Volvo", "BMW", "Ford", "Mazda"};
- A[4]
70[blank_start]int[blank_end] myNum[3] = {10, 20, 30};
- Aint
71string cars[4] = {"Volvo", "BMW", "Ford", "Mazda"};
cout << [blank_start]cars[2][blank_end];
call 3rd element- Acars[2]
72string cars[4] = {"Volvo", "BMW", "Ford", "Mazda"};
cars[[blank_start]2[blank_end]] = "Opel";
cout << cars[2];
change the 3rd list itrm- A2
73string cars[4] = {"Volvo", "BMW", "Ford", "Mazda"};
for(int i = 0; i < 4; i++) {
cout << i << ": " << cars[blank_start][i][blank_end] << "\n";
}- A[i]
74string cars[] = {"Volvo", "BMW", "Ford"}; // size of array is always [blank_start]3[blank_end]
- A3
75string cars[5] = {"Volvo", "BMW", "Ford"}; // size of array is [blank_start]5[blank_end], even though it's only three elements inside it
- A5
76string cars[5] = {"Volvo", "BMW", "Ford"}; // size of array is 5, even though it's only three elements inside it
[blank_start]cars[[blank_end]3] = "Mazda";
cars[4] = "Tesla";- Acars[
77It is also possible to declare an array without specifying the elements on declaration, and add them later:
[blank_start]string[blank_end] cars[5];
cars[0] = "Volvo";
cars[1] = "BMW";- Astring
78string food = "Pizza"; // food variable
string [blank_start]&[blank_end]meal = food; // reference to food- A&
79string food = "Pizza";
cout << [blank_start]&[blank_end]food; // Outputs 0x6dfed4- A&
80string food = "Pizza"; // A food variable of type string
cout << food; // Outputs the value of food (Pizza)
cout << [blank_start]&[blank_end]food; // Outputs the memory address of food (0x6dfed4)- A&
81string food = "Pizza"; // A food variable of type string
[blank_start]string*[blank_end] ptr = &food; // A pointer variable, with the name ptr, that stores the address of food
cout << &food << "\n";
cout << ptr << "\n";- Astring*
82// Create a function
[blank_start]void myFunction()[blank_end] {
cout << "I just got executed!";
}
int main() {
myFunction(); // call the function
return 0;
}
// Outputs "I just got executed!"- Avoid myFunction()
83void myFunction([blank_start]string fname[blank_end]) {
cout << fname << " Refsnes\n";
}
int main() {
myFunction("Liam");
myFunction("Jenny");
myFunction("Anja");
return 0;
}
// Liam Refsnes
// Jenny Refsnes
// Anja Refsnes- Astring fname
84void myFunction(string country [blank_start]=[blank_end] "Norway") {
cout << country << "\n";
}
int main() {
myFunction("Sweden");
myFunction("India");
myFunction();
myFunction("USA");
return 0;
}
// Sweden
// India
// Norway
// USA- A=
85void myFunction([blank_start]string fname,int age[blank_end]) {
cout << fname << " Refsnes. " << age << " years old. \n";
}
int main() {
myFunction("Liam", 3);
myFunction("Jenny", 14);
myFunction("Anja", 30);
return 0;
}
// Liam Refsnes. 3 years old.
// Jenny Refsnes. 14 years old.
// Anja Refsnes. 30 years old.- Astring fname,int age
86int myFunction(int x) {
[blank_start]return[blank_end] 5 + x;
}
int main() {
cout << myFunction(3);
return 0;
}
// Outputs 8 (5 + 3)- Areturn
87int myFunction([blank_start]int x,int y[blank_end]) {
return x + y;
}
int main() {
cout << myFunction(5, 3);
return 0;
}
// Outputs 8 (5 + 3)- Aint x,int y
88int myFunction(int x, int y) {
return x + y;
}
int main() {
[blank_start]int[blank_end] z = myFunction(5, 3);
cout << z;
return 0;
}
// Outputs 8 (5 + 3)- Aint
89int plusFunc(int x, int y) {
return x + y;
}
double plusFunc(double x, double y) {
return x + y;
}
int [blank_start]main()[blank_end] {
int myNum1 = plusFunc(8, 5);
double myNum2 = plusFunc(4.3, 6.26);
cout << "Int: " << myNum1 << "\n";
cout << "Double: " << myNum2;
return 0;
}- Amain()
Information
- Description
- Computer Science Quiz on C++, created by revanth naidu on 01/04/2021.
- Author
- revanth naidu
- Language
- English
- Views
- 0
- Tags
- Rating
- No ratings yet Rate this quiz
More on C++ Programming Basics